import threading
import redis
import time
import yappi

HOST = "127.0.0.1"
PORT = "6379"
DB = 0
ZLIST_NAME = "idList"


class RedisThread(threading.Thread):
    def __init__(self, id):
        threading.Thread.__init__(self)
        # pool = redis.ConnectionPool(host=HOST, port=PORT, db=DB)
        # self.sr = redis.StrictRedis(connection_pool=pool)
        self.id = id

    def run(self):
        # book_id = self.sr.lpop(ZLIST_NAME)
        book_id = 9
        if book_id:
            print("%s start process id %s" % (self.name, book_id))
            time.sleep(10)
        else:
            print("no ids")


if __name__ == "__main__":
    yappi.set_clock_type("cpu")
    yappi.set_clock_type("wall")
    yappi.start()
    thread_num = 300
    while thread_num:
        thread = RedisThread(thread_num)
        thread.start()
        # thread.join()
        thread_num -= 1
    main_thread = threading.current_thread()
    for t in threading.enumerate():
        if t is not main_thread:
            t.join()

    yappi.get_func_stats().print_all()
    yappi.get_thread_stats().print_all()

    print("all done!")



